<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<jsp:include page="global.jsp"></jsp:include>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>售后处理类型管理</title>
<style type="text/css">
.ctl{
	text-decoration: none;
	color: blue;
	margin: auto 7px;
}
.ctl:HOVER{
	text-decoration: underline;
}
.center{
	text-align: center;
}
</style>
</head>
<body>
	<table id="dg" class="easyui-datagrid" title="售后处理类型管理"
			data-options="
				rownumbers:true,
				iconCls: 'icon-edit',
				singleSelect: true,
				toolbar: '#tb',
				singleSelect:true,
				pagination:true,
				fit:true,
				fitColumns:true,
				pageList:[20,25,30,35,40,45,50],
				pageSize:20
			">
		<thead>
			<tr>				
				<th data-options="field:'ck',checkbox:true"></th>
				<th data-options="field:'name',width:80,align:'center'">售后处理类型名称</th>
				<th data-options="field:'remark',width:270,align:'center'">描述</th>
				<th data-options="field:'id',width:130,align:'center',formatter:formatControl">管理</th>
			</tr>
		</thead>
	</table>

	<div id="tb" style="height:auto">
		<div>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="clearForm('form', 'addItem')">新增</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-tip', plain:true" onclick="changeOrderNumber('up')">上移</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-tip', plain:true" onclick="changeOrderNumber('down')">下移</a>
		</div>
		<div>			
			售后处理类型名称: <input class="easyui-textbox" type="text" id="name" style="width:240px;height:25px;">
			<a href="javascript:search()" class="easyui-linkbutton" iconCls="icon-search">查 找</a>
		</div>
	</div>
	
	<div id="addItem" class="easyui-window" title="新增售后处理类型" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:500px; height:250px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<form id="form" method="post" action="editAftersaleHandleType" style = "width:100%; height: 100%">
					<table width="100%" height="100%">
						<tr>
							<td style="width: 150px align="right">售后处理类型名称：</td>
							<td>
								<input class="easyui-textbox" name="name" data-options="required:true" style="width: 300px;" />
							</td>
						</tr>
						<tr>
							<td align="right">描述：</td>
							<td>
								<input class="easyui-textbox" data-options="multiline:true" style="width: 300px; height: 80px;" name="remark">
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="$('#form').submit()" style="width:80px">确 定</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:$('#addItem').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	
	<script type="text/javascript">
		function formatControl(val, row){
			//return '<a class="ctl" href="javascript:void(0)" onclick="lookDetail(\'' + row.orderNumber + '\', \'' + row.name + '\', \'' + row.remark + '\')">查看</a> <a class="ctl" href="javascript:void(0)" onclick="editDept(' + val + ',' + row.orderNumber + ', \'' + row.name + '\', \'' + row.remark + '\')">编辑</a> <a class="ctl" href="javascript:void(0)" onclick="delDept(' + val + ')">删除</a>';
			return '<a class="ctl" href="javascript:void(0)" onclick="lookDetail(\'' + row.name + '\',  \'' + row.remark + '\')">查看</a>'+
			' <a class="ctl" href="javascript:void(0)" onclick="editAftersaleHandleType(' + val + ',' + row.orderNumber + ', \'' + row.name + '\', \'' + row.remark + '\')">编辑</a>'+
			' <a class="ctl" href="javascript:void(0)" onclick="delAftersaleHandleType(' + val + ')">删除</a>';
		}
		function search(){
			var dg = $("#dg");
			var name = $("#name").textbox("getValue").trim();
			//var url = "queryDept?pageSize="+opts.pageSize +"&moduleCode=" + moduleCode + "&menuname=" + menuName;
			var url = "queryAftersaleHandleType?name=" + name;
			//loadTableData(url);
			dg.datagrid('reload', url);
		}
		function lookDetail(name, remark){			
			$("#lookName").textbox("setValue", name);
			$("#lookRemark").textbox("setValue", remark);
			
			$('#lookDetail').window('open');
		}
		function editAftersaleHandleType(id, orderNumber, name, remark){
			$("#editId").val(id);
			$("#editOrderNumber").val(orderNumber);
			$("#editName").textbox("setValue", name);
			$("#editRemark").textbox("setValue", remark);
			
			$('#editItem').window('open');
		}
		function delAftersaleHandleType(id){
			$.messager.confirm("删除确认", "您确定要删除所选的售后处理类型吗？", function(r){
				if(r){
					data = "id=" + id;
					$.ajax({
					  type: "GET",
					  url: "delAftersaleHandleType",
					  data: data,
					  success:function(data){
						  	var val = $.parseJSON(data);
							if(val.success){
								bottomRight('提示', '操作成功！');
								$('#dg').datagrid('reload');
							}else{
								$.messager.alert("提示", val.msg, "error");
							}
					  }
					});
				}
			});
		}
		$(function(){
			$("#form").form({
				onSubmit: function(){
					var isValid = $(this).form('validate');
					return isValid;	// 返回false将停止form提交 
			    },
				success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						bottomRight('提示', '操作成功！');
						$('#dg').datagrid('reload');
						$('#addItem').window('close');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
				}
			});
			$("#editForm").form({
				onSubmit: function(){
					var isValid = $(this).form('validate');
					return isValid;	// 返回false将停止form提交 
			    },
				success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						bottomRight('提示', '操作成功！');
						$('#dg').datagrid('reload');
						$('#editItem').window('close');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
				}
			});

			search();
		});
		
		function changeOrderNumber(type){
			var dg = $("#dg");
			var row = $('#dg').datagrid('getSelected');
			if (!row){
				return;
			}
			var targetId = getSelections(row, type);
			if (!targetId){
				return;
			}
			var params = "id=" + row.id + "&targetId=" + targetId;
			$.ajax({
			  type: "GET",
			  url: "aftersaleHandleTypeChangeOrderNumber",
			  data: params,
			  success:function(data){
			  	var val = $.parseJSON(data);
				if(val.success){
					bottomRight('提示', '操作成功！');
					$('#dg').datagrid('reload');
				}else{
					$.messager.alert("提示", val.msg, "error");
				}
			  }
			});
		}
		function getSelections(r, type){
			var rows = $('#dg').datagrid('getRows');
			var len = rows.length;
			for(var i=0; i < len; i++){
				var row = rows[i];
				if(row.id == r.id){
					if(type == "up" && i > 0){
						return rows[i - 1].id;
					}else if(type == "down" && i < len - 1){
						return rows[i + 1].id;
					}
				}
			}
			return null;
		}
		
	</script>
	
	
	<div id="lookDetail" class="easyui-window" title="售后处理类型详情" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:500px; height:250px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<table width="100%" height="100%">
					<tr>
						<td style="width: 150px align="right">售后处理类型名称：</td>
						<td>
							<input class="easyui-textbox" id="lookName" readonly="readonly" style="width: 300px;" />
						</td>
					</tr>
					<tr>
						<td align="right">描述：</td>
						<td>
							<input class="easyui-textbox" id="lookRemark" style="width: 300px; height: 80px;" data-options="multiline:true" readonly="readonly" />
						</td>
					</tr>
				</table>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="javascript:$('#lookDetail').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	
	<div id="editItem" class="easyui-window" title="编辑售后处理类型" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:530px; height:250px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<form id="editForm" method="post" action="editAftersaleHandleType" style = "width:100%; height: 100%">
					<input type="hidden" id="editId" name = "id">
					<input type="hidden" id="editOrderNumber" name = "orderNumber">
					<table width="100%" height="100%">
						<tr>
							<td style="width: 170px align="right">售后处理类型名称：</td>
							<td>
								<input class="easyui-textbox" name="name" id="editName" data-options="required:true" style="width: 300px;" />
							</td>
						</tr>
						<tr>
							<td align="right">描述：</td>
							<td colspan="3"><input class="easyui-textbox" data-options="multiline:true" style="width: 300px; height: 80px;" name="remark" id="editRemark"></td>
						</tr>
					</table>
				</form>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="$('#editForm').submit()" style="width:80px">确 定</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:$('#editItem').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>

</body>
</html>